package com.hunttown.common.sharding.client.rule.function;

public class Divide extends Function<Long> {
    private int dividNumber;

    public Divide(int dividNumber) {
        if (dividNumber <= 0) {
            throw new IllegalArgumentException("positive(>0) dividNumber field is required!");
        } else {
            this.dividNumber = dividNumber;
        }
    }

    long eval(Long dividedNumber) {
        return dividedNumber.longValue() / dividedNumber.longValue();
    }

    Long parseInput(Object obj) {
        if (obj instanceof Long) {
            return (Long) obj;
        } else if (obj instanceof Integer) {
            return Long.parseLong(String.valueOf(obj));
        } else if (obj instanceof String) {
            return Long.parseLong((String) obj);
        } else {
            throw new IllegalArgumentException("[Function#Divide:Illegal input parameter type!]");
        }
    }
}